<?php

class SiteStatus extends \Eloquent
{
    public static function newUser()
    {
        self::collect('new_user');
    }
    public static function newTopic()
    {
        self::collect('new_topic');
    }
    public static function newLab()
    {
        self::collect('new_lab');
    }
    public static function newEvaluation()
    {
        self::collect('new_evaluation');
    }
    public static function newIssue()
    {
        self::collect('new_issue');
    }
    public static function newComment()
    {
        self::collect('new_comment');
    }
    public static function newOpinion()
    {
        self::collect('new_opinion');
    }
    public static function newSection()
    {
        self::collect('new_section');
    }
    public static function newReport()
    {
        self::collect('new_report');
    }
    public static function newReply()
    {
        self::collect('new_reply');
    }
    public static function newImage()
    {
        self::collect('new_image');
    }

    /**
     * Collection site status
     *
     * @param  [string] $action
     * @return void
     */
    public static function collect($subject)
    {
        $today = Carbon::now()->toDateString();

        if (!$todayStatus = SiteStatus::where('day', $today)->first()) {
            $todayStatus = new SiteStatus;
            $todayStatus->day = $today;
        }

        switch ($subject) {
            case 'new_user':
                $todayStatus->register_count += 1;
                break;
            case 'new_topic':
                $todayStatus->topic_count += 1;
                break;
            case 'new_lab':
                $todayStatus->lab_count += 1;
                break;
            case 'new_issue':
                $todayStatus->issue_count += 1;
                break;
            case 'new_image':
                $todayStatus->image_count += 1;
                break;
        }

        $todayStatus->save();
    }
}
